<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>封装日期格式化函数</title>
</head>
<body>
    <script>
        const date = new Date("1990-4-5 12:45:45");
        // console.log(date.getFullYear());
        // console.log(date.getMonth() + 1);
        // console.log(date.getDate());
        // console.log(date.getHours());
        // console.log(date.getMinutes());
        // console.log(date.getSeconds());


        function dateFormate(date,formate = "XXX-YY-DD HH:MM:SS") {
            const config = {
                XXX : date.getFullYear(),
                YY : ((date.getMonth() + 1) <= 9) ? `0${(date.getMonth() + 1)}` : (date.getMonth() + 1),
                DD : (date.getDate() <= 9) ? `0${date.getDate()}` : date.getDate(),
                HH : date.getHours(),
                MM : date.getMinutes(),
                SS : date.getSeconds()
            }

            for (const key in config) {
                formate = formate.replace(key,config[key]);
            }

            return formate;
        }

        console.log(dateFormate(date,"XXX年YY月DD日HH时MM分SS秒"));
    </script>
</body>
</html>